//
//  BKMacros.h
//  Pods
//
//  Created by sentinel on 2020/3/16.
//

#ifndef BKMacros_h
#define BKMacros_h

#define APP                 [UIApplication sharedApplication]
#define APP_DELEGATE         [[UIApplication sharedApplication] delegate]
#define APP_ROOT_CONTROLLER  (id)[(id)[[UIApplication sharedApplication] delegate] rootViewController]
#define APP_WIN_ROOT_CONTROLLER  (id)[[(id)[[UIApplication sharedApplication] delegate] window] rootViewController]
#define APP_KEY_WIN        [[UIApplication sharedApplication] keyWindow]


#define DLOG(...)  NSLog(@"[DEBUG][%s] - [line:%d] %@",__func__, __LINE__, [NSString stringWithFormat:__VA_ARGS__]);

#define DISPATCH_RELEASE(__OBJ__)   if(__OBJ__) { dispatch_release(__OBJ__); __OBJ__ = NULL; }
#define RELEASE(__POINTER)      [__POINTER release]; __POINTER = nil;
#define RETAIN(__POINTER)       [__POINTER retain]
#define AUTORELEASE(__POINTER)  [__POINTER autorelease]
#define RGBCOLOR(r,g,b)         [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1]

#define NETWORK_CACHE_DIR @"http"

#define NULL2NIL(o) o == [NSNull null] ? nil : o
#define NIL2NULL(o) o == nil ? [NSNull null] : o

#define BUNDLE_INFO  [[NSBundle mainBundle] infoDictionary]

#define BUNDLE_ID [BUNDLE_INFO valueForKey:@"CFBundleIdentifier"]
#define APP_ID      [BUNDLE_INFO valueForKey:@"CFBundleIdentifier"]
#define APP_CHANNEL [DBCache valueForKey:@"app_channel"]

#define APP_VERSION ([BUNDLE_INFO valueForKey:@"CFBundleShortVersionString"]?:[BUNDLE_INFO valueForKey:@"CFBundleVersion"])
#define APP_BUILD ([BUNDLE_INFO valueForKey:@"CFBundleVersion"])
#define APP_URL_TYPES   [BUNDLE_INFO valueForKey:@"CFBundleURLTypes"]
#define APP_NAME        [BUNDLE_INFO valueForKey:@"CFBundleDisplayName"]
#define APP_URL_SCHEMES [APP_URL_TYPES count]?[[APP_URL_TYPES objectAtIndex:0] valueForKey:@"CFBundleURLSchemes"]:nil
#define APP_URL_SCHEME [APP_URL_SCHEMES count]?[APP_URL_SCHEMES objectAtIndex:0]:nil

#define IDFV ( [[UIDevice currentDevice] respondsToSelector:@selector(identifierForVendor)] ? [[[UIDevice currentDevice] identifierForVendor] UUIDString] : nil)


//#define DEVICE_ID                [OpenUDID value]
#define DEVICE_TOKEN             [DBCache valueForKey:@"device_token"]

#define DEVICE_NAME              [[UIDevice currentDevice] name]
#define DEVICE_PLATFORM          [[UIDevice currentDevice] model]
#define DEVICE_SYS_NAME                [[UIDevice currentDevice] systemName]
#define DEVICE_SYS_VERSION         [[UIDevice currentDevice] systemVersion]
#define DEVICE_RESOLUTION      [NSString stringWithFormat:@"%dx%d", (int)[[UIScreen mainScreen] bounds].size.width, (int)[[UIScreen mainScreen] bounds].size.height]

#define DEVICE_PARAM      @{@"appId":APP_ID, \
                            @"build":APP_BUILD,\
                        @"productId":APP_ID, \
                          @"channel":APP_CHANNEL?:@"", \
                          @"version":APP_VERSION, \
                         @"deviceId":@"", \
                         @"platform":DEVICE_PLATFORM,\
                               @"os":DEVICE_SYS_NAME,\
                        @"osVersion":DEVICE_SYS_VERSION, \
                       @"resolution":DEVICE_RESOLUTION, \
                       @"deviceName":DEVICE_NAME}



//notify
#define NOTIFICATION_USER_LOGOUT                @"NotificationUserLogout"
#define NOTIFICATION_USER_LOGIN                 @"NotificationUserLogin"
#define NOTIFICATION_USER_PROFILT_UPDATED       @"NotificationUserProfileUpdated"
#define NOTIFICATION_USER_WILL_CHANGE           @"NotificationUserWillChange"
#define NOTIFICATION_USER_PROFILE_REFRESH       @"NotificationUserProfileRefresh"


// AppDelegate notify
#define NOTIFICATION_APP_WILL_RESIGN_ACTIVE     @"AppWillResignActive"
#define NOTIFICATION_APP_DID_ENTER_BACKGROUND   @"AppDidEnterBackground"
#define NOTIFICATION_APP_WILL_ENTER_BACKGROUND  @"AppWillEnterBackground"
#define NOTIFICATION_APP_DID_BECOME_ACTIVE      @"AppDidBecomeActive"


//resource
#define BKCONFIG_BUNDLE [NSBundle bundleWithPath:[[NSBundle bundleForClass:self.class].resourcePath stringByAppendingPathComponent:@"config.bundle"]]
#endif /* BKMacros_h */
